﻿using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.MailMerging;
using System;
using System.Collections.Generic;
using System.Text;

namespace EcoSystem.Office.Word
{
    internal class HandleMergeFieldInsertDocument : IFieldMergingCallback
    {
        //文本处理在这里，如果写在这一块，则不起作用
        void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
        {

        }
        //图片处理在这里
        void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
        {
            if (args.DocumentFieldName.Equals("Pic"))//如果是Pic字段则处理图片
            {
                // 使用DocumentBuilder处理图片的大小
                DocumentBuilder builder = new DocumentBuilder(args.Document);
                var images = (byte[])args.FieldValue;
                Shape shape = builder.InsertImage(images);

                // 设置x,y坐标和高宽.
                shape.Left = 0;
                shape.Top = 0;
            }
        }
    }
}
